﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
namespace DotNet.Utilities.JS
{
    /// <summary>
    /// JS帮助类，帮助生成一些常用的JS
    /// </summary>
    //public class ScriptHelper
    //{

    //    public ScriptHelper()
    //    {
    //    }

    //    /// <summary>
    //    /// 生成关闭对话框的JS
    //    /// </summary>
    //    /// <param name="elementID">对话框内的任意元素ID，如果为null，则使用调用onclick的元素</param>
    //    /// <returns>返回生成的JS</returns>
    //    public string CloseDialog(string elementID = null)
    //    {
    //        string rv = "";
    //        if (!string.IsNullOrWhiteSpace(elementID))
    //        {
    //            rv = string.Format("FF_CloseDialog($('#{0}'),'{1}','{2}');", elementID, Language.Tip, Language.DataLoading);
    //        }
    //        else
    //        {
    //            rv = string.Format("FF_CloseDialog($(this),'{0}','{1}');", Language.Tip, Language.DataLoading);
    //        }
    //        return rv;
    //    }

    //    /// <summary>
    //    /// 生成打开对话框的JS
    //    /// </summary>
    //    /// <param name="url">对话框地址</param>
    //    /// <param name="title">对话框标题</param>
    //    /// <param name="width">宽度</param>
    //    /// <param name="height">高度</param>
    //    /// <param name="DialogID">对话框ID，用于触发关闭事件，如果不需要捕捉关闭事件，则不用赋值</param>
    //    /// <param name="formID">表单ID，如果对话框中只有一个表单，则不用赋值</param>
    //    /// <returns>返回生成的JS</returns>
    //    public MvcHtmlString OpenDialog(string url, string title, int? width, int? height, string DialogID = null)
    //    {
    //        if (width == null)
    //        {
    //            width = -1;
    //        }
    //        if (height == null)
    //        {
    //            height = -1;
    //        }
    //        string rv = "";
    //        if (string.IsNullOrEmpty(DialogID))
    //        {
    //            rv = string.Format("FF_OpenDialog('{0}','{1}',{2},{3});return false;", HttpUtility.UrlEncode(url), title, width, height);
    //        }
    //        else
    //        {
    //            rv = string.Format("FF_OpenDialog('{0}','{1}',{2},{3},'{4}');return false;", HttpUtility.UrlEncode(url), title, width, height, DialogID);
    //        }
    //        return MvcHtmlString.Create(rv);
    //    }

    //    /// <summary>
    //    /// 生成加载页面的JS
    //    /// </summary>
    //    /// <param name="url">页面的URL</param>
    //    /// <param name="msg">加载完毕后的提示信息</param>
    //    /// <returns>返回生成的JS</returns>
    //    //public MvcHtmlString LoadPage(string url, string msg = null)
    //    {
    //        string rv = "";
    //        rv = string.Format("FF_LoadPage('{0}',{1});return false;", HttpUtility.UrlEncode(url), string.IsNullOrEmpty(msg) ? "null" : "'" + msg + "'");
    //        return MvcHtmlString.Create(rv);
    //    }

        /// <summary>
        /// 生成上传控件的JS
        /// </summary>
        /// <param name="ButtondivID">上传按钮DIVID</param>
        /// <param name="filesize">上传文件最大限制，默认4G</param>
        /// <param name="filetypes">上传文件类型，默认*.*</param>
        /// <param name="filetypesdeskey">上传文件描述多语言key,默认为‘所有文件’</param>
        /// <param name="prefix">上传控件前缀</param>
        /// <param name="buttontextkey">上传按钮文本的多语言Key，默认为‘上传文件’</param>
        /// <param name="uploadtextkey">上传信息的多语言Key，默认为‘上传中’</param>
        /// <param name="savetextkey">保存信息的多语言Key，默认为‘保存中’</param>
        /// <param name="completetextkey">上传完毕的多语言Key，默认为‘上传完毕’</param>
        /// <param name="stoptextkey">上传中断的多语言Key，默认为‘上传中断’</param>
    //    /// <returns></returns>
    //    public MvcHtmlString UploadFiles(string ButtondivID, int filesize = 4096, string filetypes = "*.*", string filetypesdeskey = "所有文件", string prefix = "", string buttontextkey = "上传文件", string uploadtextkey = "上传中", string savetextkey = "保存中", string completetextkey = "上传完毕", string stoptextkey = "中断", string fieldName = "", bool isMultiple = false, string filename = null, string fileid = null, long? vmid = null, string vmname = null, string idfield = null)
    //    {
    //        string rv = string.Format("FF_Upload({0}, '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', '{8}', '{9}','{10}','{11}',{12},'{13}','{14}',{15},'{16}','{17}');",
    //            filesize,
    //            filetypes,
    //            Utils.GetResourceText(filetypesdeskey),
    //            ButtondivID,
    //            Utils.GetResourceText(buttontextkey),
    //            Utils.GetResourceText(uploadtextkey),
    //            Utils.GetResourceText(savetextkey),
    //            Utils.GetResourceText(completetextkey),
    //            Utils.GetResourceText(stoptextkey),
    //            Utils.GetResourceText("只能选择一个文件"),
    //            prefix,
    //            fieldName,
    //            isMultiple.ToString().ToLower(),
    //            filename,
    //            fileid,
    //            vmid == null ? 0 : vmid.Value,
    //            vmname,
    //            idfield);
    //        return MvcHtmlString.Create(rv);
    //    }
    //}
}
